﻿/*  
 *  IIS LogFile Analyser, Copyright (C) 2013. http://www.iis-analyser.com
 *  --
 *  This program is free software, provided "AS IS" WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 * 
 *  File Author: Ian Quigley,    2013-02-23
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using DataStore;

namespace Web
{
    public class Visitor
    {
        public bool IsAnonymous { get; private set; }

        public static Visitor Current
        {
            get
            {
                if (HttpContext.Current == null || HttpContext.Current.Session == null)
                    return new Visitor() { IsAnonymous = true };

                var visitor = HttpContext.Current.Session["Visitor"] as Visitor;
                if (visitor == null)
                {
                    visitor = new Visitor() { IsAnonymous = true };
                    HttpContext.Current.Session["Visitor"] = visitor;
                }

                return visitor;                
            }
        }
        
        internal void Login( AccountRecord account)
        {
            if (account != null)
                Current.IsAnonymous = false;            
        }
    }
}